<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            margin: 0px auto;
            text-align: center;
        }

        .main {
            width: 400px;
            height: 400px;
            background-color: #CFF;
        }

        .inner {
            width: 100px;
            height: 100px;
            line-height: 100px;
        }

        #div1 {
            background-color: #FF9;
            float:left;
        }

        #div2 {
            background-color: #ccf;
            float:left;
            clear: both;
        }

        #div3 {
            background-color: #CCC;
            float:right;
            clear:both;
        }
        #div4 {
            background-color: #F9C;
            float:right;
        }
    </style>
</head>
<body>
<h1>浮动案例</h1>
<hr>

<div class="main">
    <div class="inner" id="div1">
        我是DIV1
    </div>
    <div class="inner" id="div2">
        我是DIV2
    </div>
    <div class="inner" id="div3">
        我是DIV3
    </div>
    <div class="inner" id="div4">
        我是DIV4
    </div>
</div>
</body>
</html>